<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
        <style>
            .warning {
                background: gold;
            }
        </style>
    </head>
    <body>
        <div id="app">
            <btn :child-background="parentBackground">{{content}}</btn>
            <button>默认</button>
            <button>成功</button>
            <button class="warning" @click="handleChange">警告</button>
        </div>
        <template id="btn">
            <div>
                <button :class="[childBackground]"><slot></slot></button>
            </div>
        </template>
        <script src="../vue.js"></script>
        <script>
            let btn = {
                template: '#btn',
                // 父传子  
                props: ['childBackground'],
                data() {
                    return {};
                },
            };
            new Vue({
                el: '#app',
                data() {
                    return {
                        content: '默认',
                        parentBackground: '',
                    };
                },
                methods: {
                    handleChange() {
                        this.content = '警告';
                        this.parentBackground = 'warning';
                    },
                },
                components: {
                    btn,
                },
            });
        </script>
    </body>
</html>
